import React, { useEffect, useState } from "react";
import type { MenuProps } from "antd";
import { Menu } from "antd";
import { superAdminMenus, studentMenus, adminMenus } from "@/config";
import { useNavigate } from "react-router-dom";
import usePathKey from "@/hooks/usePathKey";
import { useDispatch, useSelector } from "react-redux";
import { getMenu, select_menu, select_userInfo } from "@/store/slice/userInfo";
import { get } from "http";
import { useAppDispatch } from "@/app/hooks";

const App: React.FC = () => {
	const [current, setCurrent] = useState("");
	const dispatch = useAppDispatch();
	const navigate = useNavigate();
	const menu = useSelector(select_menu);
	const pathKey = usePathKey();
	const onClick: MenuProps["onClick"] = (e) => {
		navigate(e.key);
		setCurrent(e.key);
	};

	useEffect(() => {
		if (pathKey) {
			setCurrent(pathKey);
		}
		dispatch(getMenu());
	}, []);

	return (
		<Menu
			onClick={onClick}
			selectedKeys={[current]}
			mode="horizontal"
			items={menu}
		/>
	);
};

export default App;
